<template>
  <image v-if="isImage($attrs.src)" v-bind="$attrs" mode="scaleToFill" @click="handlePreview"></image>
  <view v-else class="w-600rpx ellipsis text-#1484EE" @click="previewDocument($attrs.src)">{{ $attrs.name }}</view>
</template>

<script setup>
import { isImage, previewDocument } from '@/utils/tools.js';
const prop = defineProps({
  preview: {
    type: Boolean,
    default: true
  }
});

const attrs = useAttrs();

function handlePreview() {
  if (!prop.preview) return;
  uni.previewImage({
    current: attrs.src,
    urls: attrs?.urls || []
  });
}
</script>

<style lang="scss" scoped></style>
